package yunwo.cn.yzstation.base;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.support.multidex.MultiDexApplication;

import com.kingja.loadsir.core.LoadSir;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.Stack;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by lao on 2017/8/28.
 */

public class Yzapp extends MultiDexApplication {
    private static Yzapp singleton;
    private static Thread mainThread;//主线程
    private static int mainThreadId;//主线程id
    private static Handler mHandler;
    private SharedPreferences mInformation;
    private SharedPreferences.Editor mInformationedit;

    @Override
    public void onCreate() {
        super.onCreate();
        init();
        singleton = this;
        mainThread=Thread.currentThread();//取得当前的Thread
        mainThreadId=android.os.Process.myTid();//取得线程id，主线程id
        mInformation = getSharedPreferences("information", Context.MODE_PRIVATE);
        mInformationedit = mInformation.edit();





        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                //强制竖屏
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {

            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {

            }
        });

    }

    private void init() {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                .addInterceptor(new LoggerInterceptor("TAG"))
                .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                .readTimeout(10000L, TimeUnit.MILLISECONDS)
                //其他配置
                .build();

        OkHttpUtils.initClient(okHttpClient);


      /*  LoadSir.beginBuilder()
                .addCallback(new ErrorCallback())//'添加各种状态页
                .addCallback(new EmptyCallback())
                .addCallback(new LoadingCallback())
                .addCallback(new TimeoutCallback())
                .addCallback(new CustomCallback())
                .setDefaultCallback(LoadingCallback.class)//设置默认状态页
                .commit();*/



    }

    public SharedPreferences.Editor getinfoSPEditor() {
        return mInformationedit;
    }
    public String getUserName(){
        return mInformation.getString("username", "");
    }
    public String getmobile(){
        return mInformation.getString("mobile", "");
    }
    public String gettoken(){
        return mInformation.getString("token", "");
    }
    public String getAuthorization(){
        return mInformation.getString("Authorization", "");
    }
    public String getBeginOrgId(){  return mInformation.getString("organId", ""); }
    public String getgetBeginOrgName(){ return mInformation.getString("organName", ""); }
    public String getPackingname(){ return mInformation.getString("packName", ""); }
    public String getproductName(){return mInformation.getString("productName","");}
    public String getOrganType() {
        return mInformation.getString("OrganType","");
    }

    public static Yzapp getInstance() {
        return singleton;
    }
    public static Thread getMainThread() {
        return mainThread;
    }

    public static int getMainThreadId() {
        return mainThreadId;
    }
    public static Handler getHandler() {
        return mHandler;
    }
}
